﻿using Microsoft.EntityFrameworkCore;
using RescueApp.Data.Config;
using RescueApp.Model;

namespace RescueApp.Data
{
    public class RescueContext : DbContext
    {
        private readonly string _connectionString;

        public DbSet<RescueApply> RescueApplies { get; set; }
        public DbSet<RescueDispatch> RescueDispatches { get; set; }

        public RescueContext() : base() { }
        public RescueContext(DbContextOptions<RescueContext> options) : base(options) { }
        public RescueContext(string connectionString)
        {
            _connectionString = connectionString;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                optionsBuilder.UseSqlServer(_connectionString);
            }
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.ApplyConfiguration(new RescueApplyConfig());
            builder.ApplyConfiguration(new RescueDispatchConfig());
        }
    }
}